home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
4.1
/
Lazy.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
2KB
|
84 lines
" NAME Lazy
AUTHOR miw@cs.man.ac.uk
FUNCTION implements lazy evaluation
ST-VERSION 4.0 4.1
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1
DATE 10 Nov 1992
SUMMARY Lazy implements lazy objects (which are given a block to compute
their value, but only do so on demand) MIW.
"
'From Smalltalk-80, Version 2.2 of July 4, 1987 on 25 February 1988 at 9:51:47 pm'!
nil subclass: #Lazy
instanceVariableNames: 'result done args '
classVariableNames: ''
poolDictionaries: ''
category: 'Kernel-Processes'!
Lazy comment:
'I represent an execution which may not be required. I will
not start execution until at least one message has been
received. The messages sent to me are delayed until execution
has completed.'!
!Lazy methodsFor: 'initializing'!
block: aBlock
done := false.
result := aBlock.
args := #()!
block: aBlock value: value
done := false.
result := aBlock.
args := Array with: value!
block: aBlock value: value1 value: value2
done := false.
result := aBlock.
args := Array with: value1 with: value2!
block: aBlock value: value1 value: value2 value: value3
done := false.
result := aBlock.
args := Array with: value1 with: value2 with: value3!
block: aBlock valueWithArguments: anArray
done := false.
result := aBlock.
args := anArray! !
!Lazy methodsFor: 'evaluating'!
doesNotUnderstand: aMessage
done ifFalse: "this really should be a critical region"
[result := result valueWithArguments: args. done := true].
^result perform: aMessage selector withArguments: aMessage arguments! !
!BlockClosure methodsFor: 'lazy evaluation'!
lazyValue
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self!
lazyValue: value
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self value: value!
lazyValue: value1 value: value2
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self value: value1 value: value2!
lazyValue: value1 value: value2 value: value3
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self value: value1 value: value2 value: value3!
lazyValueWithArguments: anArray
"Return an object that knows how to evaluate me if called on to do so."
^Lazy new block: self valueWithArguments: anArray! !